package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Reference
    private UserService userService;

    //添加
    @PostMapping
    public boolean save(User user){
        return userService.save(user);
    }

    //修改
    @PutMapping
    public boolean update(User user){
        return userService.update(user);
    }

    //删除
    @DeleteMapping("/{uuid}")
    public boolean delete(@PathVariable Integer uuid){

        return userService.delete(uuid);
    }

    //查询单个user
    @GetMapping("/{uuid}")
    public User get(@PathVariable Integer uuid){

        return userService.get(uuid);
    }

    //分页查询
    @GetMapping("/{page}/{size}")
    public PageInfo<User> getAll(@PathVariable Integer page, @PathVariable Integer size){
        return  userService.getAll(page,size);
    }

    //登录,使用post隐藏密码
    @PostMapping("/loginssm")
    public User login(String userName,String password){
       return userService.login(userName,password);
    }
}
